import TerserPlugin from 'terser-webpack-plugin';
import OptimizeCssAssetsPlugin from 'optimize-css-assets-webpack-plugin';
export default {
  ssr: true,
  // personal-space-11d0b4
  render: {
    http2: {
      push: true, pushAssets: null,
    },
    timing: {
      total: true,
    },
  },

  server: {
    port: 5000, // default: 3000
    host: '127.0.0.1', // default: localhost
    // https: {
    //   key: fs.readFileSync(path.resolve(__dirname, 'certs/localhost.key')),
    //   cert: fs.readFileSync(path.resolve(__dirname, 'certs/localhost.crt'))
    // }

  },

  // Global page headers: https://go.nuxtjs.dev/config-head
  head: {
    title: 'blog',
    htmlAttrs: {
      lang: 'en',
    },
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1, shrink-to-fit=no' },
      { hid: 'description', name: 'description', content: '' },
      { name: 'format-detection', content: 'telephone=no' },
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
    ],
  },

  /*
   ** Customize the progress-bar color
   */
  loading: { color: '#fff' },

  // Global CSS (https://go.nuxtjs.dev/config-css)
  css: [
    '@/assets/css/flex.css',
  ],

  /*
   ** Plugins to load before mounting the App
   */
  plugins: [
    { src: '~/plugins/cloudbase', mode: 'client' },
    { src: '~plugins/aos', mode: 'client' },
  ],

  // Auto import components: https://go.nuxtjs.dev/config-components
  components: true,

  // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
  buildModules: [
    // https://go.nuxtjs.dev/eslint
    // '@nuxtjs/eslint-module',
    // https://go.nuxtjs.dev/stylelint
    // '@nuxtjs/stylelint-module',
    '@nuxtjs/tailwindcss',
    'nuxt-purgecss',
  ],

  purgeCSS: {
    mode: 'webpack',
    enabled: ({ isDev, isClient }) => (!isDev && isClient), // or `false` when in dev/debug mode
    paths: [
      'components/**/*.vue',
      'layouts/**/*.vue',
      'pages/**/*.vue',
      'plugins/**/*.js',
    ],
    styleExtensions: ['.css'],
    whitelist: ['body', 'html', 'nuxt-progress'],
    extractors: [
      {
        extractor: content => content.match(/[A-z0-9-:\\/]+/g) || [],
        extensions: ['html', 'vue', 'js'],
      },
    ],
  },

  // Modules: https://go.nuxtjs.dev/config-modules
  modules: [
    // https://go.nuxtjs.dev/bootstrap
    'bootstrap-vue/nuxt',
    // https://go.nuxtjs.dev/content
    '@nuxt/content',
  ],

  bootstrapVue: {
    // bootstrapCSS: false, // Or `css: false`
    // bootstrapVueCSS: false, // Or `bvCSS: false`
    // icons: true, // Install the IconsPlugin (in addition to BootStrapVue plugin
    componentPlugins: [
      'LayoutPlugin',
      'ToastPlugin',
      'ModalPlugin',
    ],
    components: [
      'BContainer',
      'BRow',
      'BCol',
      'BFormInput',
      'BButton',
      'BModal',
    ],
  },

  router: {
    base: '',
  },

  // Content module configuration: https://go.nuxtjs.dev/config-content
  // content: {
  //   markdown: {
  //     // prism: {
  //     //   theme: 'prism-themes/themes/prism-material-oceanic.css',
  //     // }
  //   },
  // },

  //
  //    "@tencent/eslint-config-tencent": "^0.15.2",
  // "@tencent/stylelint-config-tencent": "^1.0.7",
  // Build Configuration: https://go.nuxtjs.dev/config-build
  build: {
    cache: true,

    extractCSS: true,

    splitChunks: {
      layouts: false,
      pages: true,
      commons: true,
      vendors: true,
    },

    optimization: {
      minimize: true,
      // minimize: false,
      minimizer: [
        // terser-webpack-plugin
        new TerserPlugin({
          parallel: true,
          terserOptions: {
            // https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
          },
        }),

        // optimize-css-assets-webpack-plugin
        new OptimizeCssAssetsPlugin({
          assetNameRegExp: /\.css$/g,
          cssProcessor: require('cssnano'),
          cssProcessorPluginOptions: {
            preset: ['default', { discardComments: { removeAll: true } }],
          },
          canPrint: true,
        }),

      ],
      splitChunks: {
        minSize: 10000,
        maxSize: 250000,
        maxInitialRequests: 20,
        maxAsyncRequests: 20,
      },
    },

    plugins: [

    ],

    babel: {
      compact: false,
    },

    publicPath: 'https://blog.ylliuworld.com/static',
    /*
     ** You can extend webpack config here
     */
    extend() {
      // config.module.rules.push({
      //   test: /\.md$/,
      //   type: 'javascript/auto',
      //   use: [
      //     { loader: 'html-loader' },
      //     { loader: 'markdown-loader', options: {} }
      //   ],
      // })
      // Run ESLint on save
      // if (ctx.isDev && ctx.isClient) {

      // }

    },

    // analyze: {
    //   analyzerMode: 'static',
    // },

  },
};
